//
//  DeviceCell.swift
//  MTBeacon
//
//  Created by 方强 on 15/7/9.
//  Copyright (c) 2015年 MT. All rights reserved.
//

import UIKit
import MTSDK

class DeviceCell: UITableViewCell {
    @IBOutlet weak var nameView: UILabel!
    @IBOutlet weak var powerView: UILabel!
    @IBOutlet weak var rssiView: UILabel!
    @IBOutlet weak var macView: UILabel!
    @IBOutlet weak var setoverlv: UILabel!
    @IBOutlet weak var majorView: UILabel!
    @IBOutlet weak var minorView: UILabel!
    
    class func devicefmtCell() -> DeviceCell{
        let objects = UINib(nibName: "DeviceCell", bundle: nil).instantiate(withOwner: nil, options: nil);
        let obj: AnyObject = objects[0] as AnyObject;
        
        let cell = obj as! DeviceCell;
        
        return cell;
    }
    
    func refreshDis(value: MTBLEDevice){
        self.nameView.text = value.getDevice().name;
        self.rssiView.text = "Rssi:\(value.getAvgRssi())";
        
        if(value.getDevicetype() == MTBLEDevice_MTBLEDEVICETYPE.MTBLE){
            self.powerView.text = "电量:\(value.getBattery())%";
            self.macView.text  = "Mac:\(value.getMac()!)";
            
            self.powerView.isHidden = false;
            self.macView.isHidden = false;
            self.setoverlv.isHidden = true;
            self.majorView.isHidden = true;
            self.minorView.isHidden = true;
            return;
        }
        
        if(value.getDevicetype() == MTBLEDevice_MTBLEDEVICETYPE.MTBeacon3){
            self.powerView.text = "电量:\(value.getBattery())%";
            self.macView.text  = "Mac:\(value.getMac()!)";
            self.majorView.text = "major:\(value.getMajor())";
            self.minorView.text = "minor:\(value.getMinor())";
            self.setoverlv.text = "部署等级:\(MTBLEDevice.getSetLvName(index: value.getSetlev())!)";
            
            self.powerView.isHidden = false;
            self.macView.isHidden = false;
            self.majorView.isHidden = false;
            self.minorView.isHidden = false;
            self.setoverlv.isHidden = false;
            return;
        }
        
        if(value.getDevicetype() == MTBLEDevice_MTBLEDEVICETYPE.MTBeacon4){
            self.powerView.text = "电量:\(value.getBattery())%";
            self.macView.text  = "Mac:\(value.getMac()!)";
            self.majorView.text = "major:\(value.getMajor())";
            self.minorView.text = "minor:\(value.getMinor())";
            self.setoverlv.text = "部署等级:\(MTBLEDevice.getSetLvName(index: value.getSetlev())!)";
            
            self.powerView.isHidden = false;
            self.macView.isHidden = false;
            self.majorView.isHidden = false;
            self.minorView.isHidden = false;
            self.setoverlv.isHidden = false;
            return;
        }
        
        self.powerView.isHidden = true;
        self.macView.isHidden = true;
        self.majorView.isHidden = true;
        self.minorView.isHidden = true;
        self.setoverlv.isHidden = true;
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
